// generated 2005/8/8 17:10:19 CST by xihels@163.com
//


#include "config.h"
#include "MemberList.h"
#include "pixmaps.h"

MemberList::MemberList()
{
    MemberList* memberList = this;
    memberList->set_flags(Gtk::CAN_FOCUS);
    memberList->set_headers_visible(false);
    memberList->set_rules_hint(false);
    memberList->set_reorderable(false);
    memberList->set_enable_search(true);
    //memberList->set_fixed_height_mode(true);

    refListStore = Gtk::ListStore::create(columns);

    refListStore->set_default_sort_func(sigc::mem_fun(*this, &MemberList::on_sort_compare));
    refListStore->set_sort_column_id(
	    Gtk::TreeSortable::DEFAULT_SORT_COLUMN_ID,
	    Gtk::SORT_ASCENDING);

    memberList->set_model(refListStore);
    memberList->append_column("头像", columns.face);
    memberList->append_column("昵称", columns.name);
    memberList->append_column("号码", columns.uid);   
    memberList->show();
}


void MemberList::refresh(const Members& members)
{
    refListStore->set_sort_column_id(-2,
	    Gtk::SORT_ASCENDING);

    Gtk::TreeModel::Children child = refListStore->children(); 

    for_each(child.begin(), child.end(), Refresh<Members>(*this, members));
    members.forEach(AddMembers<Members>(*this));

    refListStore->set_sort_column_id(
	    Gtk::TreeSortable::DEFAULT_SORT_COLUMN_ID,
	    Gtk::SORT_ASCENDING);
}

void MemberList::refreshStatus(const Members& members)
{
    refListStore->set_sort_column_id(-2,
	    Gtk::SORT_ASCENDING);

    Gtk::TreeModel::Children child = refListStore->children(); 
    for_each(child.begin(), child.end(), RefreshStatus<Members>(*this, members));
    
    refListStore->set_sort_column_id(
	    Gtk::TreeSortable::DEFAULT_SORT_COLUMN_ID,
	    Gtk::SORT_ASCENDING);

}

int MemberList::getSelectMemberid() 
{

    Glib::RefPtr<Gtk::TreeSelection> selection = get_selection();	

    if (!selection->count_selected_rows())
	return 0;	    

    Gtk::TreeModel::iterator iter = selection->get_selected();

    return (*iter)[columns.uid];
}

